package com.cjy.address.action;

import com.cjy.address.service.AddressService;
import com.base.common.action.AbstractBaseAction;
import com.base.common.bean.ActionResult;
import com.cjy.common.bean.OpAttributes;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import javax.annotation.Resource;

import static com.base.common.GlobaConstants.*;

/**
 * 程序软件管理
 * 
 * @author Administrator
 *
 */

@Action("addressAction")
@Results({ @Result(name = ASYNCHRONOUS, type = JSON, params = { ROOT,
		ACTION_RESULT_DATA, CONTENT_TYPE, CONTENT_TYPE_JSON }) })
public class AddressAction extends AbstractBaseAction{

	private static final long serialVersionUID = 1L;
	
	@Resource
	private AddressService addressService;
	
	private int districtId;	// 县/区的id

    public int getCategory() {
        return category;
    }

    public void setCategory(int category) {
        this.category = category;
    }

    private int category;
	
	/**
	 * 获取全部地址信息列表
	 * 
	 * @return
	 */
	public String getAllAddress(){
		try {
			actionResult = ActionResult.getActionResult(new OpAttributes().add("code", 1).add("result", addressService.getAllAddress()));
		} catch (Exception e) {
			actionResult = ActionResult.getActionResult(new OpAttributes().add("code", 0));
		}
		return returnType();
	}

	/**
	 * 根据区县id获取小区信息
	 * 
	 * @return
	 */
	public String getCompoundsByDistrictId() {
		try {
			actionResult = ActionResult.getActionResult(new OpAttributes().add("code", 1).add("result", addressService.getCompoundsByDistrictId(districtId)));
		} catch (Exception e) {
			actionResult = ActionResult.getActionResult(new OpAttributes().add("code", 0));
		}
		return returnType();
	}

	public int getDistrictId() {
		return districtId;
	}
	
	public void setDistrictId(int districtId) {
		this.districtId = districtId;
	}

	public String queryCompoundsByCategory() {
		try {
			actionResult = ActionResult.getActionResult(new OpAttributes().add("code", 1).add("result", addressService.queryCompoundsByCategory(category)));
		} catch (Exception e) {
			actionResult = ActionResult.getActionResult(new OpAttributes().add("code", 0));
		}
		return returnType();
	}
	
}
